package com.cyw.baselibrary.utils;


/**
 * Created by ChenYuanWang on 2018-12-27.
 */
public class StringUtils {

    /**
     * 集合转换成指定字符分割的字符串
     * @param delimiter
     * @param elements
     * @return
     */
    public static String join(CharSequence delimiter,
                              Iterable<? extends CharSequence> elements) {
        if (elements == null) {
            return null;
        } else {
            StringBuffer sb = new StringBuffer();
            for (CharSequence cs : elements) {
                sb.append(cs);
                sb.append(delimiter);
            }
            if (sb.length() > 1) {
                return sb.subSequence(0, sb.length() - 1).toString();
            }
            return sb.toString();
        }
    }
}
